﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

using PowerCreator.LMS.Common.Script;
using PowerCreator.LMS.DL.Project.Entity;
using PowerCreator.LMS.Web.DL.Project;

public partial class sysadmin_UserInfo_EditUser : PowerCreator.LMS.Web.Base.BasePage
{

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {

            InitPage();
            BinderForm();
        }
    }
    protected override void InitPage()
    {
        radbtn_Male.Text = GetLanageValueByKey("EditUser_desc27", PowerCreator.LMS.Language.LanagetItemType.Page);
        radbtn_Female.Text = GetLanageValueByKey("EditUser_desc28", PowerCreator.LMS.Language.LanagetItemType.Page);
        btnSave.Text = GetLanageValueByKey("btn_Save", PowerCreator.LMS.Language.LanagetItemType.Page);
        btnReset.Text = GetLanageValueByKey("btn_Reset", PowerCreator.LMS.Language.LanagetItemType.Page);
        base.InitPage();
    }
    private void BinderForm()
    {
        lbl_UserName.Text = GetLoginEntity.UserName;
        int uid = GetLoginEntity.UserID;
        TOAdvancedUser obj = new TOAdvancedUser();
        VOTOAdvancedUser vo = new VOTOAdvancedUser();
        vo = obj.Load(uid);

        txt_Email.Text = vo.Email;

        txt_MobileTelephone.Text = vo.Mobile;
        txt_RealName.Text = vo.Name;
        if (vo.Sex)
            radbtn_Male.Checked = true;
        else
            radbtn_Female.Checked = true;

    }
    private bool CheckPageData()
    {
        if (!string.IsNullOrEmpty(txt_Email.Text))
        {
            if (!PowerCreator.LMS.Common.Utils.PageValidate.IsEmail(txt_Email.Text))
            {
                lbl_msg_Error.Text = GetLanageValueByKey("EditorTeacher_msg_g3", PowerCreator.LMS.Language.LanagetItemType.Page);
                txt_Email.BackColor = System.Drawing.Color.BlanchedAlmond;
                txt_Email.Focus();
                return false;
            }
        }
        if (!string.IsNullOrEmpty(txt_MobileTelephone.Text))
        {
            if (!PowerCreator.LMS.Common.Utils.PageValidate.IsNumber(txt_MobileTelephone.Text))
            {
                lbl_msg_Error.Text = GetLanageValueByKey("EditorTeacher_msg_g5", PowerCreator.LMS.Language.LanagetItemType.Page);
                txt_MobileTelephone.BackColor = System.Drawing.Color.BlanchedAlmond;
                txt_MobileTelephone.Focus();
                return false;
            }
        }

        return true;
    }
    protected void btnSave_Click(object sender, EventArgs e)
    {
        if (!CheckPageData()) return;
        int uid = GetLoginEntity.UserID;
        TOAdvancedUser obj = new TOAdvancedUser();
        VOTOAdvancedUser vo = new VOTOAdvancedUser();

        vo = obj.Load(uid);
        vo.Email = txt_Email.Text;
        vo.Mobile = txt_MobileTelephone.Text;
        vo.Name = txt_RealName.Text;
        if (radbtn_Male.Checked == true)
            vo.Sex = true;
        else
            vo.Sex = false;

        if (obj.Update(vo))
        {
            string url = "EditUser.aspx";
            Script.RedirectURL(url);
        }

    }
    protected void btnReset_Click(object sender, EventArgs e)
    {
        string url = "EditUser.aspx";
        Script.RedirectURL(url);
    }
}
